package app;

import swing.*;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

public class Main {
    public static final int WINDOW_WIDTH = 450;
    public static final int WINDOW_HEIGHT = 600;
    public static int viewChange = 0;
    public static final Object object = new Object();



        public static void main(String[] args) throws IOException {
        // 获得屏幕的分辨率，初始化 Frame
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        JFrame frame = new JFrame("校园猫管理平台");
        frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        frame.setResizable(false);
        //设置窗口的大小和位置,居中放置
        frame.setBounds(((int) screenSize.getWidth() - WINDOW_WIDTH) / 2, ((int) screenSize.getHeight() - WINDOW_HEIGHT) / 2,
                WINDOW_WIDTH, WINDOW_HEIGHT);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel currentView = null;


        while(true){
            if(viewChange == -1){
                break;
            }else {
                if (currentView != null) {
                    frame.getContentPane().removeAll();
                    frame.repaint();
                }
                switch (viewChange) {
                    case 1:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Register.jpg").getImage());
                        RegisterView registerView = new RegisterView();
                        currentView.setLayout(null);
                        registerView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(registerView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 2:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Login.jpeg").getImage());
                        LoginView loginView = new LoginView();
                        currentView.setLayout(null);
                        loginView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(loginView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 3:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Menu.jpeg").getImage());
                        MenuView menuView = new MenuView();
                        currentView.setLayout(null);
                        menuView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(menuView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 4:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/List.png").getImage());
                        ListView listView = new ListView();
                        listView.showCat();
                        currentView.setLayout(null);
                        listView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(listView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 5:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Add.jpeg").getImage());
                        AddView addView = new AddView();
                        currentView.setLayout(null);
                        addView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(addView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 6:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Clock.jpeg").getImage());
                        ClockView clockView = new ClockView();
                        currentView.setLayout(null);
                        clockView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(clockView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 7:
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Feed.jpeg").getImage());
                        FeedView feedView = new FeedView();
                        currentView.setLayout(null);
                        feedView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(feedView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                    case 0:
                    default:
                        // 背景图片JPanel
                        currentView = new BackgroundPanel(new ImageIcon("src/img/Main.jpg").getImage());
                        MainView mainView = new MainView();
                        // 背景JPanel添加JPanel0 简单缩放一下
                        currentView.setLayout(null);
                        mainView.JPanel0.setBounds(0, 0, WINDOW_WIDTH * 29 / 30, WINDOW_HEIGHT * 19 / 20);
                        currentView.add(mainView.JPanel0);
                        frame.add(currentView);
                        frame.setVisible(true);
                        break;
                }
                synchronized (object) {
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }
}
